﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla;

namespace Sync.Library
{
    [Serializable]
    public class Column:BusinessBase<Column>
    {
        string name = "";
        string remoteName = "";
        string dBType = "";
        private bool isNullable = true;
        private bool selected = false;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public string RemoteName
        {
            get { return remoteName; }
            set { remoteName = value; }
        }

        public string DBType
        {
            get { return dBType; }
            set { dBType = value; }
        }

        public bool IsNullable
        {
            get { return isNullable; }
            set { isNullable = value; }
        }
        
        public bool Selected
        {
            get { return selected; }
            set { selected = value; }
        }

        public Column(string name, string dBType)
        {
            this.name = name;
            this.dBType = dBType;
        }

        private Column()
        {

        }

        public static Column GetColumn(Csla.Data.SafeDataReader dr)
        {
            Column c = new Column();
            c.Fetch(dr);
            return c;
        }

        private void Fetch(Csla.Data.SafeDataReader dr)
        {
            name = dr.GetString("name");
            isNullable = dr.GetBoolean("is_nullable");
            selected = isNullable == false;
        }

        
    }
}
